<template>
  <div class="hero">
    <!-- 头部 -->
    <div class="topbar bg-black py-2 px-3 d-flex ai-center text-white">
      <img src="../assets/logo.png" height="30" />
      <div class="px-2 flex-1">
        <span>王者荣耀</span>
        <span class="ml-3">攻略站</span>
      </div>
      <router-link to="/" tag="div">
        <span class="mr-2">更多英雄</span> <span>&gt;</span>
      </router-link>
    </div>

    <!-- 页面banner -->
    <div
      class="top"
      :style="{ 'background-image': `url(${model.banner})` }"
      v-if="model"
    >
      <div class="info text-white p-3 h-100 d-flex flex-column jc-end">
        <div class="fs-sm">{{ model.title }}</div>
        <h2 class="my-2">{{ model.name }}</h2>
        <div class="fs-sm">
          {{ model.categories.map((v) => v.name).join("/") }}
        </div>
        <div class="d-flex jc-between pt-2">
          <div class="scores d-flex ai-center" v-if="model.scores">
            <span>难度</span>
            <span class="badge bg-primary">{{ model.scores.difficult }}</span>
            <span>技能</span>
            <span class="badge bg-info">{{ model.scores.skills }}</span>
            <span>攻击</span>
            <span class="badge bg-danger">{{ model.scores.attack }}</span>
            <span>生存</span>
            <span class="badge bg-dark-1">{{ model.scores.survive }}</span>
          </div>
          <router-link to="/" tag="span" class="text-light-1 fs-sm">
            皮肤:2 &gt;
          </router-link>
        </div>
      </div>
    </div>

    <!-- 内容 -->
    <div v-if="model">
      <div class="bg-white px-3">
        <div class="nav d-flex pt-3 pb-2 jc-around border-bottom">
          <div class="nav-item active">
            <div class="nav-link">英雄初识</div>
          </div>
          <div class="nav-item">
            <div class="nav-link">进阶攻略</div>
          </div>
        </div>
      </div>
      <swiper>
        <swiper-slide>
          <div>
            <!-- 技能板块 -->
            <div class="p-3 bg-white border-bottom">
              <!-- 按钮 -->
              <div class="d-flex">
                <router-link to="/" tag="button" class="btn flex-1 btn-lg">
                  <i class="iconfont icon-vedio"></i>
                  英雄介绍视频
                </router-link>
                <router-link to="/" tag="button" class="btn btn-lg flex-1 ml-2">
                  <i class="iconfont icon-card-hero"></i>
                  一图识英雄
                </router-link>
              </div>
              <!-- 技能 -->
              <div class="skills mt-4">
                <div class="d-flex jc-around">
                  <img
                    class="icon"
                    @click="currentSkillIndex = i"
                    :class="{ active: currentSkillIndex == i }"
                    :src="item.icon"
                    v-for="(item, i) in model.skills"
                    :key="i"
                  />
                </div>
                <div v-if="currentSkill">
                  <div class="d-flex py-4">
                    <h3 class="m-0">{{ currentSkill.name }}</h3>
                    <span class="text-grey-1 ml-4">
                      (冷却值:{{ currentSkill.delay }} 消耗:{{
                        currentSkill.cost
                      }})
                    </span>
                  </div>
                  <p class="mt-2">{{ currentSkill.description }}</p>
                  <div class="border-bottom"></div>
                  <p class="text-grey-1">小提示：{{ currentSkill.tips }}</p>
                </div>
              </div>
            </div>
            <!-- 出装推荐 -->
            <my-card plain icon="Menu" title="出装推荐" class="hero-items">
              <div class="fs-xl">顺风出装</div>
              <div class="d-flex jc-around text-center fs-sm mt-3">
                <div v-for="(item, i) in model.items1" :key="i">
                  <img class="icon" :src="item.icon" :alt="item.name" />
                  <div class="my-2">{{ item.name }}</div>
                </div>
              </div>
              <div class="border-bottom"></div>
              <div class="fs-xl mt-3">逆风出装</div>
              <div class="d-flex jc-around text-center fs-sm mt-3">
                <div v-for="(item, i) in model.items2" :key="i">
                  <img class="icon" :src="item.icon" :alt="item.name" />
                  <div class="my-2">{{ item.name }}</div>
                </div>
              </div>
            </my-card>
            <!-- 使用技巧 -->
            <my-card plain icon="Menu" title="使用技巧">
              <p class="m-0">{{ model.usageTips }}</p>
            </my-card>
            <!-- 对抗技巧 -->
            <my-card plain icon="Menu" title="对抗技巧">
              <p class="m-0">{{ model.battleTips }}</p>
            </my-card>
            <!-- 团战思路 -->
            <my-card plain icon="Menu" title="团战思路">
              <p class="m-0">{{ model.teamTips }}</p>
            </my-card>
            <!-- 英雄关系 -->
            <my-card plain icon="Menu" title="英雄关系">
              <div class="fs-xl">最佳搭档</div>
              <div
                v-for="(item, i) in model.partners"
                :key="i"
                class="d-flex mt-3"
              >
                <img :src="item.hero.avatar" height="50" />
                <p class="flex-1 m-0 ml-3">
                  {{ item.description }}
                </p>
              </div>
              <div class="border-bottom mt-3"></div>
            </my-card>
          </div>
        </swiper-slide>
      </swiper>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    id: { required: true },
  },
  data() {
    return {
      model: null,
      currentSkillIndex: 0,
    };
  },
  mounted() {
    this.fetch();
  },
  methods: {
    fetch() {
      this.$http.get(`heroes/${this.id}`).then((res) => {
        this.model = res.data;
      });
    },
  },
  computed: {
    currentSkill() {
      return this.model.skills[this.currentSkillIndex];
    },
  },
};
</script>

<style lang="scss">
@import "../assets/scss/_variables.scss";
.hero {
  .top {
    height: 50vw;
    background: #fff no-repeat top center;
    background-size: 100% 100%;
  }
  .info {
    background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 1));
    .scores {
      .badge {
        margin: 0 0.25rem;
        display: inline-block;
        width: 1rem;
        height: 1rem;
        line-height: 0.9rem;
        text-align: center;
        border-radius: 50%;
        font-size: 0.6rem;
        border: 1px solid rgba(255, 255, 255, 0.2);
      }
    }
  }
  .skills {
    img.icon {
      width: 5.3846rem;
      height: 5.3846rem;
      border: 3px solid map-get($map: $colors, $key: "white");
      border-radius: 50%;
      &.active {
        border-color: map-get($map: $colors, $key: "primary");
      }
    }
  }
  .hero-items {
    img.icon {
      width: 3.8462rem;
      height: 3.8462rem;
      border-radius: 50%;
    }
  }
}
</style>
